package com.tanchengjin.admin.modules.blog.controller;

import com.github.pagehelper.PageInfo;
import com.tanchengjin.admin.modules.blog.service.ArticleService;
import com.tanchengjin.admin.modules.cms.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/{id}")
    public String getArticleByCategoryId(Model view, @PathVariable(required = true) Integer id, @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(defaultValue = "10", required = false) int size) {
        PageInfo<Article> articleList = articleService.getArticleListByCategoryId(id, page, size);
        view.addAttribute("articleList", articleList);
        view.addAttribute("urlValue", "category/" + id);
        view.addAttribute("categoryId", id);
        return "/index/index";
    }
}
